package com.bw.house.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bw.house.R
import com.bw.house.entity.HouseAreaEntity
import com.bw.house.entity.HouseEntityItem
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class HouseAreaAdapter():BaseQuickAdapter<HouseAreaEntity,BaseViewHolder>(R.layout.item_dong) {
    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: HouseAreaEntity) {
        holder.getView<TextView>(R.id.dong).text = "${item.dong}栋"
        holder.getView<TextView>(R.id.area).text = "${item.area}m²"
        val adapter = HouseAdapter()
        adapter.addData(item.list)
        val rv = holder.getView<RecyclerView>(R.id.rv_dong)
        val drop = holder.getView<ImageView>(R.id.drop_down)
        drop.setOnClickListener {
            if (rv.visibility == View.GONE){
                rv.visibility = View.VISIBLE
                drop.setImageResource(R.drawable.baseline_keyboard_arrow_up_24)
            }else{
                rv.visibility = View.GONE
                drop.setImageResource(R.drawable.baseline_keyboard_arrow_down_24)
            }
        }
        rv.adapter = adapter
    }
}
//房源数据item
class HouseAdapter():BaseQuickAdapter<HouseEntityItem,BaseViewHolder>(R.layout.item_house){
    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: HouseEntityItem) {
        holder.getView<TextView>(R.id.fy_mh).text = "${item.id}室"
        holder.getView<TextView>(R.id.fy_gs).text = item.enterpriseName
        holder.getView<TextView>(R.id.fy_mj).text = "${item.area}m²"

        when(item.rented){
            false->{
                holder.getView<TextView>(R.id.fy_zt).text = "空闲"
                holder.setTextColor(R.id.fy_zt,Color.parseColor("#0BA8ED"))
                holder.getView<TextView>(R.id.fy_zt).setBackgroundResource(R.drawable.item_bg1)
            }

            true->{
                holder.getView<TextView>(R.id.fy_zt).text = "已租"
                holder.setTextColor(R.id.fy_zt,Color.parseColor("#A0C95F"))
                holder.getView<TextView>(R.id.fy_zt).setBackgroundResource(R.drawable.item_bg2)
            }
        }
    }

}